﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Windows.Forms;

using ExtBusiness;
using ExtBusiness.User;
using ExtBusiness.FlowOperation;

public partial class WebPubManager_WorkPowerManager :PageBase
{
    private WorkFlowPubSettting wfpsTemp = new WorkFlowPubSettting();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataTable dtSource = SystemConfig.GetSetting("注册用户不需预审");

            if (dtSource.Rows.Count > 0)
            {
                cbxYhsz.Checked = dtSource.Rows[0]["value"].ToString() == "1" ? true : false;               
            }
            BindFlowName();
            BindFlowType();
            BindDepList();
            BindInterfaceSet();
            BindWeb();
        }
    }

    /// <summary>
    /// 保存注册用户预审设置
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnRefer_Click(object sender, EventArgs e)
    {
        int nYhsz = cbxYhsz.Checked ? 1 : 0;
        SystemConfig.StoreSetting(cbxYhsz.Text, nYhsz);
    }

    /// <summary>
    /// 大厅申报接口地址设置 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSaveFace_Click(object sender, EventArgs e)
    {      
        string  strFaceType = cbInterfaceType.Checked ? "1" : "0";
        wfpsTemp.UpdateInterfaceType(txtInterfaceUrl.Text.Trim(), strFaceType, ddlWorkflowFace.SelectedItem.Value);
    }

    /// <summary>
    /// 绑定所有流程名称
    /// </summary>
    public void BindFlowName()
    {
        DataTable dtTable = wfpsTemp.GetSelectOptions("");
        ddlControl.Items.Clear();
        foreach (DataRow row in dtTable.Rows)
        {
            ddlControl.Items.Add(new ListItem(row["KEYVALUE"].ToString(), row["KEYCODE"].ToString()));
        }
        //设置默认值
        ViewState["FlowName"] = ddlControl.SelectedItem.Text;
        ViewState["NameID"] = ddlControl.SelectedItem.Value;
    }

    protected void ddlControl_SelectedIndexChanged(object sender, EventArgs e)
    {
        ViewState["FlowName"] = ddlControl.SelectedItem.Text;
        ViewState["NameID"] = ddlControl.SelectedItem.Value;
    }

    /// <summary>
    /// 绑定所有流程别名
    /// </summary>
    public void BindFlowType()
    {
        DataTable dtTable = wfpsTemp.GetWorkFlow();
        ddlWorkflow.Items.Clear();
        ddlWorkflowFace.Items.Clear();
        foreach (DataRow row in dtTable.Rows)
        {
            ddlWorkflow.Items.Add(new ListItem(row["KEYVALUE"].ToString(), row["KEYCODE"].ToString()));
            ddlWorkflowFace.Items.Add(new ListItem(row["KEYVALUE"].ToString(), row["KEYCODE"].ToString()));
        }
        //设置默认值
        ViewState["FlowType"] = ddlWorkflow.SelectedItem.Text;
        ViewState["TypeID"] = ddlWorkflow.SelectedItem.Value;
    }

    /// <summary>
    /// 绑定咨询部门
    /// </summary>
    public void BindDepList()
    {
        DepartHandle dhTemp = new DepartHandle();
        DataTable dtTable = dhTemp.GetDepList();
        ddlDep.Items.Clear();
        foreach (DataRow row in dtTable.Rows)
        {
            ddlDep.Items.Add(new ListItem(row["depart_name"].ToString(), row["departid"].ToString()));
        }
        //设置默认值
        ViewState["DepID"] = ddlDep.SelectedItem.Value;
        ViewState["DepName"] = ddlDep.SelectedItem.Text;
    }

    /// <summary>
    /// 绑定大厅申报接口地址设置
    /// </summary>
    /// <!--addby zhongjian 20091214-->
    public void BindInterfaceSet()
    {
        string strID = ddlWorkflowFace.SelectedItem.Value;
        DataTable dtTemp = wfpsTemp.GetAllPubWorkFlow(strID);
        if (dtTemp.Rows.Count > 0)
        {
            cbInterfaceType.Checked = dtTemp.Rows[0]["INTERFACETYPE"].ToString() == "0" ? false : true;
            txtInterfaceUrl.Text = dtTemp.Rows[0]["INTERFACEURL"].ToString();
        }
    }

    protected void ddlWorkflow_SelectedIndexChanged(object sender, EventArgs e)
    {
        ViewState["FlowType"] = ddlWorkflow.SelectedItem.Text;
        ViewState["TypeID"] = ddlWorkflow.SelectedItem.Value;
    }

    /// <summary>
    /// 接口流程选择
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ddlWorkflowFace_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindInterfaceSet();
    }

    protected void ddldep_SelectedIndexChanged(object sender, EventArgs e)
    {
        ViewState["DepID"] = ddlDep.SelectedItem.Value;
        ViewState["DepName"] = ddlDep.SelectedItem.Text;
    }

    /// <summary>
    /// 保存地信数据交互地址设置 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSaveWeb_Click(object sender, EventArgs e)
    {
        string strWebFlag = cbWebService.Checked ? "1" : "0";
        wfpsTemp.UpdateWebService(txtWebServiceUrl.Text.Trim(), strWebFlag);
    }

    /// <summary>
    /// 绑定地信数据交互地址设置 
    /// </summary>
    /// <!--addby zhongjian 20100702-->
    protected void BindWeb()
    {
        DataTable dtTemp = wfpsTemp.GetWebService();
        if (dtTemp.Rows.Count > 0)
        {
            cbWebService.Checked = dtTemp.Rows[0]["webflag"].ToString() == "0" ? false : true;
            txtWebServiceUrl.Text = dtTemp.Rows[0]["weburl"].ToString();
        }
    }
}
